package com.hyk.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyk.domain.CoinWithdraw;
import com.hyk.dto.R;
import com.hyk.service.CoinWithdrawService;
import com.hyk.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@Api(tags = "提币记录控制器")
@RequestMapping("/coinWithdraws")
public class CoinWithdrawsController {

    @Resource
    private CoinWithdrawService coinWithdrawService;

    @GetMapping("/records")
    @ApiOperation("按条件分页查询")
    public R<Page<CoinWithdraw>> list(@ApiIgnore Page<CoinWithdraw> page,
                                      Long coinId,
                                      Long userId,
                                      String userName,
                                      String mobile,
                                      Byte status,
                                      String endAmount,
                                      String startAmount,
                                      String startTime,
                                      String endTime){
        Page<CoinWithdraw> list = coinWithdrawService.findByPage(page,coinId,userId,userName,mobile,status,startAmount,endAmount,startTime,endTime);
        return R.ok(list);
    }

    @GetMapping("/user/record")
    public R<Page<CoinWithdraw>> list(Page<CoinWithdraw> page, Long coinId) {
        Page<CoinWithdraw> list = coinWithdrawService.page(page, new LambdaQueryWrapper<CoinWithdraw>()
                .eq(CoinWithdraw::getUserId, UserUtils.getUser())
                .eq(coinId != null, CoinWithdraw::getCoinId, coinId)
                .orderByDesc(CoinWithdraw::getCreated));
        return R.ok(list);
    }

}
